package com.skyolder.milkbee.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.skyolder.milkbee.domain.Comment;
import com.skyolder.milkbee.dto.CardComment;
import com.skyolder.milkbee.dto.HisPost;

/**
 * Spring Data JPA repository for the Comment entity.
 */
public interface CommentRepository extends JpaRepository<Comment,Long> {

	Page<Comment> findByCardId(Long cardId, Pageable pageable);
	@Query("select new com.skyolder.milkbee.dto.CardComment(c.id, c.seq, c.categoryId,c.content,c.createdAt,c.userId,c.author, le.avatar,le.mana,c.light,le.authentication,es.name,le.underwrite) from  Comment c,Leaguer le , Estate es where c.cardId=?1 and c.userId=le.userId and le.estateRank=es.rank ")
	Page<CardComment> doQueryCardCommentsByCardId(Long cardId, Pageable pageable);
	
	Page<Comment> findByUserId(Long userId, Pageable pageable);
	
	@Query("from  Comment c where c.categoryId in(?1) and c.accusation>0")
	Page<Comment> doqueryInCategories(List<Long> categoryIds, Pageable pageable);
	
	@Query("select new com.skyolder.milkbee.dto.HisPost(c.id, ca.title, c.content,c.createdAt,c.cardId) from  Comment c,Card ca  where c.userId=?1 and ca.userId=?1 and c.cardId=ca.id ")
	Page<HisPost> doQueryByUserId(Long userId, Pageable pageable);
}
